package com.gonsin.gview.logic.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.io.File;

@Configuration
public class GViewWebMvcConfig implements WebMvcConfigurer {

    @Autowired(required = false) private GViewFileProperties fileProperties;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        if(fileProperties == null){
            fileProperties = new GViewFileProperties();
        }
        registry.addResourceHandler("/view/**").addResourceLocations("classpath:\\gview\\");
        registry.addResourceHandler("/view/view").addResourceLocations("classpath:\\gview\\index.html");
        registry.addResourceHandler("/temp/**").addResourceLocations("file:" + fileProperties.getTempPath() + File.separator);
    }
}
